package com.cms.cmsbackend.controller;

import com.cms.cmsbackend.pojo.Customer;
import com.cms.cmsbackend.service.CustomerService;
import com.cms.cmsbackend.util.JwtTokenUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "用户管理")
@RequestMapping("/Customer")
public class CustomerController {

    @Autowired
    private CustomerService customerService;


    @PostMapping("/login")
    public String login(String username,String password){

        //调用service去进行查询数据
        Customer customer=customerService.select(username,password);
        //customer != null 用户名密码存在，登录成功
        if (customer != null){
            String token= JwtTokenUtils.createToken(username);
            return token;
        }
        else {
            return "登录失败";
        }
    }
}
